package org.dromara.wx;

import com.github.sd4324530.fastweixin.api.config.ApiConfig;
import com.github.sd4324530.fastweixin.handle.EventHandle;
import com.github.sd4324530.fastweixin.handle.MessageHandle;
import com.github.sd4324530.fastweixin.message.BaseMsg;
import com.github.sd4324530.fastweixin.message.req.BaseEvent;
import org.dromara.system.domain.vo.SysAccountVo;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class AdminWeixinSupport extends WeixinSupport {

    SysAccountVo account;
    List<MessageHandle> messageHandles;
    List<EventHandle> eventHandles;

    public AdminWeixinSupport(SysAccountVo account) {
        this.account = account;
    }

    public AdminWeixinSupport(SysAccountVo account, Collection<MessageHandle> messageHandles, Collection<EventHandle> eventHandles) {
        this.account = account;
        this.messageHandles = new ArrayList<>();
        this.messageHandles.addAll(messageHandles);
        this.eventHandles = new ArrayList<>();
        this.eventHandles.addAll(eventHandles);
    }

    @Override
    protected String getToken() {
        return account.getToken();
    }

    @Override
    public ApiConfig getApiConfig() {
        return account;
    }

    /**
     * 子类重写，加入自定义的微信消息处理器，细化消息的处理
     *
     * @return 微信消息处理器列表
     */
    protected List<MessageHandle> initMessageHandles() {
        return messageHandles;
    }

    /**
     * 子类重写，加入自定义的微信事件处理器，细化消息的处理
     *
     * @return 微信事件处理器列表
     */
    protected List<EventHandle> initEventHandles() {
        return eventHandles;
    }

    /**
     * 公众号APPID，使用消息加密模式时用户自行设置
     *
     * @return 微信公众平台提供的appid
     */
    protected String getAppId() {
        return account.getWxAppId();
    }

    /**
     * 加密的密钥，使用消息加密模式时用户自行设置
     *
     * @return 用户自定义的密钥
     */
    protected String getAESKey() {
        return account.getAesKey();
    }


    /**
     * 处理添加关注事件，有需要时子类重写
     *
     * @param event 添加关注事件对象
     * @return 响应消息对象
     */
    protected BaseMsg handleSubscribe(BaseEvent event) {
        return null;
    }
}
